PRT3_VERSION = "3.1.0.07.08.30"

IPARM_TYPE = "PRT3_Type"
IPARM_SHAPE = "PRT3_Shape"
IPARM_COUNT = "PRT3_Count"

# SIMULATION
IPARM_EMISSIONANGLE = "PRT3_AngleOfEmission"
IPARM_EMISSION = "PRT3_RateOfEmission"
IPARM_RECYCLE = "PRT3_Recycle"
IPARM_LIFESPAN = "PRT3_Lifespan"
IPARM_START = "PRT3_Start"
IPARM_END = "PRT3_End"
IPARM_GRAVITY = "PRT3_Gravity"
IPARM_ATTRACTION = "PRT3_AttractionStrength"
IPARM_RANGE = "PRT3_AttractionRange"
IPARM_FALLOFF = "PRT3_AttractionFalloff"
IPARM_DAMPENING = "PRT3_Dampening"

# VELOCITY
IPARM_VELOCITYX = "PRT3_VelocityX"
IPARM_VELOCITYY = "PRT3_VelocityY"
IPARM_VELOCITYZ = "PRT3_VelocityZ"
IPARM_ACCELERATIONX = "PRT3_AccelerationX"
IPARM_ACCELERATIONY = "PRT3_AccelerationY"
IPARM_ACCELERATIONZ = "PRT3_AccelerationZ"
IPARM_VELOCITYVAR = "PRT3_VelocityVar"

# ORBIT
IPARM_ORBITX = "PRT3_OrbitX"
IPARM_ORBITY = "PRT3_OrbitY"
IPARM_ORBITZ = "PRT3_OrbitZ"
IPARM_ORBITAX = "PRT3_OrbitAX"
IPARM_ORBITAY = "PRT3_OrbitAY"
IPARM_ORBITAZ = "PRT3_OrbitAZ"
IPARM_ORBITVAR = "PRT3_OrbitVar"

# SPIN
IPARM_SPINX = "PRT3_SpinX"
IPARM_SPINY = "PRT3_SpinY"
IPARM_SPINZ = "PRT3_SpinZ"
IPARM_SPINAX = "PRT3_SpinAX"
IPARM_SPINAY = "PRT3_SpinAY"
IPARM_SPINAZ = "PRT3_SpinAZ"
IPARM_SPINVAR = "PRT3_SpinVar"

# GROW
IPARM_GROWX = "PRT3_GrowX"
IPARM_GROWY = "PRT3_GrowY"
IPARM_GROWZ = "PRT3_GrowZ"
IPARM_GROWAX = "PRT3_GrowAX"
IPARM_GROWAY = "PRT3_GrowAY"
IPARM_GROWAZ = "PRT3_GrowAZ"
IPARM_GROWVAR = "PRT3_GrowVar"

# PARTICLE TRANSFORM
IPARM_PSCALE = "PRT3_PScale"
IPARM_PXSCALE = "PRT3_PXScale"
IPARM_PYSCALE = "PRT3_PYScale"
IPARM_PZSCALE = "PRT3_PZScale"
IPARM_PXROTATE = "PRT3_PXRotate"
IPARM_PYROTATE = "PRT3_PYRotate"
IPARM_PZROTATE = "PRT3_PZRotate"
IPARM_PXTRAN = "PRT3_PXTrans"
IPARM_PYTRAN = "PRT3_PYTrans"
IPARM_PZTRAN = "PRT3_PZTrans"

# HIDDEN
IPARM_ID = "PRT3_SysId"
IPARM_LIFE = "PRT3_Life"
IPARM_SPAWNPNTX = "PRT3_SpawnPntX"
IPARM_SPAWNPNTY = "PRT3_SpawnPntY"
IPARM_SPAWNPNTZ = "PRT3_SpawnPntZ"
IPARM_SPAWNVECX = "PRT3_SpawnVecX"
IPARM_SPAWNVECY = "PRT3_SpawnVecY"
IPARM_SPAWNVECZ = "PRT3_SpawnVecZ"

# SCALE MODIFIERS
IPARM_XSCALEMOD = "PRT3_xScaleMod"
IPARM_YSCALEMOD = "PRT3_yScaleMod"
IPARM_ZSCALEMOD = "PRT3_zScaleMod"

PARM_ID = "PRT3_SysId"
PARM_TYPE = "Type"
PARM_SHAPE = "Shape"
PARM_COUNT = "Count"
PARM_EMISSION = "Rate of Emission"
PARM_RECYCLE = "Recycle Particles"
PARM_LIFESPAN = "Particle Lifespan"
PARM_START = "Start Frame"
PARM_END = "End Frame"
PARM_GRAVITY = "Gravity"
PARM_VARIANCE = "Variance"
PARM_VELOCITYX = "Velocity X"
PARM_VELOCITYY = "Velocity Y"
PARM_VELOCITYZ = "Velocity Z"
PARM_ACCELERATIONX = "Acceleration X"
PARM_ACCELERATIONY = "Acceleration Y"
PARM_ACCELERATIONZ = "Acceleration Z"
PARM_VELOCITYVAR = "Velocity Variance"
PARM_ORBITX = "Orbit X"
PARM_ORBITY = "Orbit Y"
PARM_ORBITZ = "Orbit Z"
PARM_ORBITAX = "Orbit Acceleration X"
PARM_ORBITAY = "Orbit Acceleration Y"
PARM_ORBITAZ = "Orbit Acceleration Z"
PARM_ORBITVAR = "Orbit Variance"
PARM_SPINX = "Spin X"
PARM_SPINY = "Spin Y"
PARM_SPINZ = "Spin Z"
PARM_SPINAX = "Spin Acceleration X"
PARM_SPINAY = "Spin Acceleration Y"
PARM_SPINAZ = "Spin Acceleration Z"
PARM_SPINVAR = "Spin Variance"
PARM_GROWX = "Grow X"
PARM_GROWY = "Grow Y"
PARM_GROWZ = "Grow Z"
PARM_GROWAX = "Grow Acceleration X"
PARM_GROWAY = "Grow Acceleration Y"
PARM_GROWAZ = "Grow Acceleration Z"
PARM_GROWVAR = "Grow Variance"
PARM_PSCALE = "Initial Scale"
PARM_PXSCALE = "Initial xScale"
PARM_PYSCALE = "Initial yScale"
PARM_PZSCALE = "Initial zScale"
PARM_PXROTATE = "Initial xRotate"
PARM_PYROTATE = "Initial yRotate"
PARM_PZROTATE = "Initial zRotate"
PARM_PXTRAN = "Initial xOffset"
PARM_PYTRAN = "Initial yOffset"
PARM_PZTRAN = "Initial zOffset"
PARM_XSCALEMOD = "PRT3_xScaleMod"
PARM_YSCALEMOD = "PRT3_yScaleMod"
PARM_ZSCALEMOD = "PRT3_zScaleMod"
PARM_LIFE = "Life"
PARM_SPAWNPNTX = "Spawn Point X"
PARM_SPAWNPNTY = "Spawn Point Y"
PARM_SPAWNPNTZ = "Spawn Point Z"
PARM_SPAWNVECX = "Spawn Vector X"
PARM_SPAWNVECY = "Spawn Vector Y"
PARM_SPAWNVECZ = "Spawn Vector Z"
PARM_EMISSIONANGLE = "Angle of Emission"
PARM_ATTRACTION = "Strength"
PARM_RANGE = "Range"
PARM_FALLOFF = "Falloff"
PARM_DAMPENING = "Dampening"

SYSTEM_TYPE = 0;
EMITTER_TYPE = 1;
GROUP_TYPE = 2;
PARTICLE_TYPE = 3;
ATTRACTOR_TYPE = 4;
DEFLECTOR_TYPE = 5;

SHAPE_CUSTOM = 0
SHAPE_BALL = 1
SHAPE_TORUS = 2
SHAPE_PILL = 3
SHAPE_SPRITE = 4
SHAPE_CONE = 5

GEOM_EMITTER = ":Runtime:Python:PoseWorks:Particles3:resources:emitter3.obj"
GEOM_ATTRACTOR = ":Runtime:Python:PoseWorks:Particles3:resources:attractor.obj"
GEOM_DEFLECTOR = ":Runtime:Python:PoseWorks:Particles3:resources:deflector.obj"
GEOM_BALL = ":Runtime:Python:PoseWorks:Particles3:resources:ball.obj"
GEOM_TORUS = ":Runtime:Python:PoseWorks:Particles3:resources:torus.obj"
GEOM_PILL = ":Runtime:Python:PoseWorks:Particles3:resources:pill.obj"
GEOM_SPRITE = ":Runtime:Python:PoseWorks:Particles3:resources:sprite.obj"
GEOM_CONE = ":Runtime:Python:PoseWorks:Particles3:resources:cone.obj"

import os, poser
DIR_HOME = os.path.dirname(poser.AppLocation())
DIR_PRT3 = os.path.join(DIR_HOME, "Runtime", "Python", "PoseWorks", "Particles3")
DIR_DATA = os.path.join(DIR_PRT3, "data")
DIR_RESOURCES = os.path.join(DIR_PRT3, "resources")
DIR_WACROS = os.path.join(DIR_PRT3, "wacros")
DIR_TEMP = os.path.join(DIR_PRT3, "temp")
if not os.path.exists(DIR_TEMP):
	os.makedirs(DIR_TEMP)
DIR_PRESETS = os.path.join(DIR_HOME, "Runtime", "libraries", "Pose", "Particles 3 Presets")

class PwParticles3Prefs(object):
	def __init__(self):
		self.prefsPath = os.path.join(DIR_DATA, "particles3.pref")
		self.default = { "shape": GEOM_BALL,
						 "count": 30,
						 "name": "Particle Figure",
						 "dirShape": DIR_RESOURCES,
						 "lastActor": None,
						 "simInPlace": 0,
						 "simFig": 0,
						 "simChecked": {},
						 "dirPreset": DIR_PRESETS}
		self.readPrefs()
	def readPrefs(self):
		try:
			prefs = open(self.prefsPath, "r")
			data = prefs.read()
			prefs.close()
			self.prefs = self.default
			self.prefs.update( eval(data) )
		except:
			self.prefs = self.default
	def writePrefs(self):
		try:
			prefs = open(self.prefsPath, "w")
			prefs.write( repr(self.prefs) )
			prefs.close()
		except:
			pass
	def Set(self, key, value):
		self.prefs[key] = value
		self.writePrefs()
	def Get(self, key):
		return self.prefs[key]

class PwParticles3ScenePrefs(object):
	def __init__(self):
		self.prefs = {}
		if (float(poser.Version()) < 7):
			try:
					self.animset = poser.Scene().AnimSet("Particles3Prefs")
			except:
					self.animset = poser.Scene().CreateAnimSet("Particles3Prefs")
			for pref, value in self.animset.Attributes():
					self.prefs[pref] = value
	def find(self, key):
		if hasattr(self, "animset"):
			for pref, value in self.animset.Attributes():
				if pref == key:
					return value
		else:
			return None
	def Get(self, key):
		if self.prefs.has_key(key):
			value = self.prefs[key]
			if isinstance(value, str) and value == "True":
				return 1
			elif isinstance(value, str) and value == "False":
				return 0
			elif isinstance(value, str) and value.find(";") != -1:
				return value.split(";")
			else:
				try:
					return int(value)
				except:
					return value
		else:
			return 0
	def Set(self, key, value):
		self.prefs[key] = value
		if isinstance(value, list):
			import string
			value = string.join(value, ";")
		elif isinstance(value, str):
			pass
		else:
			value = repr(value)
		if hasattr(self, "animset"):
			try:
				self.animset.RemoveAttribute(key, self.find(key))
			except:
				pass
			self.animset.AddAttribute(key, value)
		else:
			return

PRT3_PREFS = PwParticles3Prefs()
PRT3_SCENEPREFS = PwParticles3ScenePrefs()
